package com.jdy.nettle.controller;


import com.jdy.entity.FrameUser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * RestController会将返回的数据转换成json返回
 */
@RestController
public class EchoController {
    @Value("${server.servlet.context-path}")
    private String projectName;

    @GetMapping("/echo")
    public String echo(String message){
        return "[ECHO] :....111111111111 " + message;
    }

    @GetMapping("/user/{id}/{name}")
    public FrameUser getUser(@PathVariable Integer id, @PathVariable String name){
        FrameUser user = new FrameUser();
        user.setRowIndex(id);
        user.setUserName(name);
        return user;
    }

    @GetMapping("/hello")
    public String hello(){
        return "Hello Spring Boot!";
    }

    @GetMapping("/get")
    public Map<String, Object> get(@RequestParam String name){
        Map<String, Object> map = new HashMap<>();
        map.put("Name", name);
        map.put("Value", projectName);
        return map;
    }
}
